package com.deruan.hotcore.resource.gui.tree;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

public class ResultTreeNode extends DefaultMutableTreeNode
{
	private String name;
	
	public ResultTreeNode(String name)
	{
		super();
		this.name = name;
	}

	public String getNameString() {
		return name;
	}

	public void setContactNameString(String contactNameString) {
		this.name = contactNameString;
	}
	
	public TreePath getSelectionTreePath()
	{
		return new TreePath(getPathToRoot(this, 0));
	}
	
	protected TreeNode[] getPathToRoot(TreeNode aNode, int depth) {
		TreeNode[] retNodes;

		if (aNode == null) {
			if (depth == 0) {
				return null;
			} else {
				retNodes = new TreeNode[depth];
			}
		} else {
			depth++;
			retNodes = getPathToRoot(aNode.getParent(), depth);
			retNodes[retNodes.length - depth] = aNode;
		}

		return retNodes;
	}
}
